package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.BusinessProcessMainMapper;
import com.zygh.policeasset.pojo.BusinessProcessMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BusinessProcessMainService {
    @Autowired
    BusinessProcessMainMapper businessProcessMainMapper;

    public BusinessProcessMain queryById(Integer id) {
        return this.businessProcessMainMapper.queryById(id);
    }

    public PageInfo queryAll(int pageNum, int pageSize, BusinessProcessMain businessProcessMain) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.businessProcessMainMapper.queryAll(businessProcessMain));
    }

    public CommonResult insert(BusinessProcessMain businessProcessMain) {
        businessProcessMain.setCreateTime(DateUtil.now());
        if (this.businessProcessMainMapper.insert(businessProcessMain) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    public CommonResult update(BusinessProcessMain businessProcessMain) {
        if (this.businessProcessMainMapper.update(businessProcessMain) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    public CommonResult deleteById(Integer id) {
        if (this.businessProcessMainMapper.deleteById(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }
}